package com.example.myapplication6;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;

public class Step1Fragment extends Fragment {
    private Order order;
    private String[] busLines = {"101路（市中心→郊区）", "102路（郊区→市中心）", "103路（环线）"};

    // 接收MainActivity传递的订单对象
    public void setOrder(Order order) {
        this.order = order;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_step, container, false);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        LinearLayout llContent = view.findViewById(R.id.ll_content);
        Button btnNext = view.findViewById(R.id.btn_next);

        // 设置标题
        tvTitle.setText("步骤1：选择巴士线路");

        // 动态添加巴士线路列表
        for (String line : busLines) {
            TextView tvBus = (TextView) inflater.inflate(R.layout.item_bus, llContent, false);
            tvBus.setText(line);
            tvBus.setOnClickListener(v -> {
                order.busLine = line; // 保存选择的线路
                btnNext.setEnabled(true); // 选中后才允许下一步
            });
            llContent.addView(tvBus);
        }

        // 下一步按钮（默认禁用，选完线路才启用）
        btnNext.setEnabled(false);
        btnNext.setOnClickListener(v -> ((MainActivity) getActivity()).goToStep(1));

        return view;
    }
}